// index.js
const util = require('../../../util/util.js')
// const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

Page({
  // onShareAppMessage() {
  //   return {
  //     title: 'tabs',
  //     path: 'page/weui/example/tabs/tabs'
  //   }
  // },
  data: {
    columns: [{
      key: '排名',
      title: '排名',
      width: 60,
      fixed: 'left',
      align: 'center'
    },
    {
      key: '区域',
      title: '区域',
      width: 100,
    }, {
      key: '道路总数',
      title: '道路总数',
      width: 100,
      fixed: 'left'
    }, {
      key: '作业道路数',
      title: '作业道路数',
      width: 120
    }, {
      key: '作业率',
      title: '作业率',
      width: 100
    }
    ],
    dataTable: [],
    tabs: [{
      title: '全市',
    },
    {
      title: '中心城区',
    },
    {
      title: '滨海新区',
    },
    {
      title: '新五区',
    }],
    activeTab: 0,
  },
  onLoad: function () {
    this.getCarRealtimeInfo(this.data.activeTab)
  },
  // 获取信息
  getCarRealtimeInfo (index) {
    var indexTitle = this.data.tabs[index].title
    console.log(indexTitle)
    var CLIENT_NO = wx.getStorageSync("CLIENT_NO");
    var that = this;
    const currentDate = new Date();
    currentDate.setDate(currentDate.getDate() - 1);
    wx.request({
      // Vehicle/GetRoadWorkInfoCity?date=2025-03-09&distance=0.01&type=全市&ClientNo=00000
      url: 'https://www.ejingyou.cn/ServerHuanwei/CompanyapiBDEapi/Vehicle/GetRoadWorkInfoCity',
      data: {
        type: indexTitle,
        ClientNo: CLIENT_NO,
        distance: '0.01',
        date: util.formatDateTime(currentDate, true),
      },
      header: {
        'content-type': 'application/json' // 默认值     
      },
      success: (res) => {
        res.data.shift();
        that.setData({
          dataTable: res.data
        });
        console.log(that.data.dataTable)
      }
    })
  },
  // table 方法
  onChange (e) {
    console.log(e)
    const index = e.detail.index
    this.setData({
      activeTab: index
    })
    this.getCarRealtimeInfo(index)
  },
  // table 方法
  onRowClick (e) {
    console.log('单击列表行')
    console.log(e.detail.value) // 点击行的数据
    wx.navigateTo({
      url: '../roadTaskStatistics/roadTaskStatistics?clientNo=' + '0000009'
    })
    
  },
})
